package lagou.mode3;

import java.util.*;
/*准备一个 HashMap 集合，统计字符串"123,456,789,123,456"中每个数字字符串出现的次数并打印出来。*/

public class Homework3 {
    public static void main(String[] args) {
        String s1="123,456,789,123,456";
        //按照逗号对字符串内容进行切割
        String[] sArr=s1.split(",");
        HashMap<String,Integer> h1=new HashMap<>();
        for(int i=0;i<sArr.length;i++){
            if(h1.containsKey(sArr[i])){
                int a=h1.get(sArr[i]);
                a++;
                h1.put(sArr[i],a);
            }
            else {
                h1.put(sArr[i],1);
            }
        }
        for(Map.Entry<String, Integer> en:h1.entrySet()){
            System.out.println(en.getKey()+"出现了"+en.getValue()+"次");
        }
    }


}
